<template>
  <div class="classi-fication">
    <!-- 操作区 -->
    <div class="topWrap">
      <el-button type="success" plain icon="el-icon-refresh" size="small" @click="init">刷新</el-button>
      <el-button type="primary" plain icon="el-icon-plus" size="small">新增</el-button>
    </div>
    <!-- 表格 -->
    <el-table stripe border :data="tableData" v-loading="tableLoading">
      <el-table-column label="ID" align="center" prop="id" min-width="27%">
        <template v-slot="{ row }">
          <div @click="handleid(row)">{{row.id}}</div>
        </template>
      </el-table-column>
      <el-table-column label="资源类型" align="center" prop="type" min-width="27%"></el-table-column>
      <el-table-column label="备注" prop="description" align="center" min-width="27%"></el-table-column>
      <el-table-column label="操作" min-width="19%"></el-table-column>
    </el-table>

    <!-- dialog区 添加设备 -->
    <el-dialog
      width="45%"
      title="资源详细"
      :visible="visible"
      :close-on-click-modal="false"
      :close-on-press-escape="false"
      :before-close="closeDialog"
    >
      <el-container class="firstBox">
        <el-header>基础信息</el-header>
        <el-main>
          <el-form label-width="80px">
            <el-form-item label="ID:">
              <el-input v-model="id"></el-input>
            </el-form-item>
            <el-form-item label="资源类型:">
              <el-input v-model="type"></el-input>
            </el-form-item>
            <el-form-item label="备注:">
              <el-input v-model="description"></el-input>
            </el-form-item>
          </el-form>
        </el-main>
      </el-container>
      <el-container class="secondBox">
        <el-header>配置信息</el-header>
        <el-main>
          <el-form label-width="170px">
            <el-form-item label="reconnect_interval:">
              <el-input v-model="reconnect_interval"></el-input>
            </el-form-item>
            <el-form-item label="pool_size:">
              <el-input v-model="pool_size"></el-input>
            </el-form-item>
            <el-form-item label="mountpoint:">
              <el-input v-model="mountpoint"></el-input>
            </el-form-item>
            <el-form-item label="disk_cache:">
              <el-input v-model="disk_cache"></el-input>
            </el-form-item>
            <el-form-item label="batch_size:">
              <el-input v-model="batch_size"></el-input>
            </el-form-item>
            <el-form-item label="address:">
              <el-input v-model="address"></el-input>
            </el-form-item>
          </el-form>
        </el-main>
      </el-container>

      <template #footer>
        <el-button type="primary" @click="closeDialog">确定</el-button>
      </template>
    </el-dialog>
  </div>
</template>

<script>
export default {
  name: "classi-fication",
  data() {
    return {
      tableData: [],
      tableLoading: false,
      // dialog
      visible: false,
      id: "",
      type: "",
      description: "",
      // ----
      reconnect_interval: "",
      pool_size: "",
      mountpoint: "",
      disk_cache: "",
      batch_size: "",
      address: ""
    };
  },
  methods: {
    // 根据当前页&每页展示条数，从服务器获取列表数据
    async init() {
      this.tableLoading = true;
      try {
        let { code, data } = await this.$http.resource.resources();
        if (code === 0) {
          this.tableData = data;
        } else {
          this.tableData = [];
        }
      } catch (_) {
        _;
      }
      this.tableLoading = false;
    },
    // 绑定dialog
    handleid(row) {
      let data=row.config;
      this.id = row.id;
      this.type = row.type;
      this.description = row.description;
      // -------
      this.reconnect_interval=data.reconnect_interval;
      this.pool_size=data.pool_size;
      this.mountpoint=data.mountpoint;
      this.disk_cache=data.disk_cache;
      this.batch_size=data.batch_size;
      this.address=data.address;
      
      this.visible = true;
    },
    // 关闭dialog
    closeDialog() {
      this.visible = false;
    }
  },
  created() {
    this.init();
  }
};
</script>

<style lang="less" scoped>
.classi-fication {
  width: 100%;
  margin: 10px;
}
.topWrap {
  width: 100%;
  height: 60px;
  box-sizing: border-box;
  display: flex;
  align-items: center;
  background-color: #fff;
  padding-left: 20px;
}
.el-table {
  box-sizing: border-box;
  width: 100%;
  background-color: #fff;
  padding: 15px 20px 20px 20px;
  box-sizing: border-box;
}
/deep/tbody > tr td:first-child {
  color: #1890ff;
  cursor: pointer;
}
.el-container {
  width: 100%;
  border-radius: 4px;
  box-shadow: 0 2px 12px 0 rgb(0 0 0 / 10%);
}
.el-container.firstBox {
  height: 215px;
}
.el-container.secondBox {
  height: 340px;
  margin-top: 10px;
}
.el-header {
  background-color: #fff;
  border-bottom: 1px solid #e6ebf5;
  color: #333;
  text-align: left;
  line-height: 35px !important;
  height: 35px !important;
}
.el-main {
  background-color: #fff;
  color: #333;
  text-align: left;
  overflow: hidden;
}
/deep/.el-main .el-form-item {
  height: 20px;
}
/deep/.el-main .el-form-item__label {
  font-size: 14px;
  color: #606266;
  font-weight: 600;
}
/deep/.el-main .el-form-item .el-input__inner {
  border: 1px solid transparent;
}
</style>